package advert_api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"zswei.xyz/manager/global"
	"zswei.xyz/manager/models"
	"zswei.xyz/manager/models/res"
)

// AdvertRemoveView 删除广告【批量】
//
//	@Tags			广告管理
//	@Summary		删除广告【批量】
//	@Description	删除广告【批量】接口
//	@Param			data	body	models.RemoveRequest	true	"删除广告列表参数"
//	@Router			/v2/advert/deleteAdvert [delete]
//	@Produce		json
//	@Success		200	{object}	res.Response{}
func (AdvertApi) AdvertRemoveView(c *gin.Context) {
	var cr models.RemoveRequest

	err := c.ShouldBindJSON(&cr)
	if err != nil {
		res.FailWithCode(res.ArgumentError, c)
		return
	}

	var advertList []models.AdvertModel
	count := global.DB.Find(&advertList, cr.IDList).RowsAffected
	if count == 0 {
		res.FailWithDesc("未找到删除项", c)
		return
	}

	//	删除广告
	global.DB.Delete(&advertList)
	res.OkWithData(fmt.Sprintf("成功删除 %d 个广告", count), c)
}
